package datatransformation;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;

import output.FileWriter;

import database.DatabaseConnector;

public class DataGetter {
	
	DatabaseConnector dbconnector;
	Computer computer;
	ArrayList<float[]> resultList;
	ArrayList<String> additionalInformation;
	int sldC=0;
	int numberOfSlds=0;

	
	public DataGetter(){
		this.dbconnector = new DatabaseConnector();
		this.resultList = new ArrayList<float[]>();
		this.additionalInformation = new ArrayList<String>();
	}
	
	
	public void readlines() {
		ResultSet result;
		result = dbconnector.query("SELECT * FROM durchfuehrung");
		try {
			int i = 1;
			while (result.next()){
				if (i>61 && i<103){
				ArrayList<String> resultArray = new ArrayList<String>(); 
				resultArray.add(result.getString("ID"));
				resultArray.add(result.getString("geschlecht"));
				resultArray.add(result.getString("jahrgang"));
				resultArray.add(result.getString("abschluss"));
				resultArray.add(result.getString("beruf"));
				resultArray.add(result.getString("ergebnisper"));
				resultArray.add(result.getString("ergebnissld"));
				resultArray.add(result.getString("orderfield"));
				resultArray.add(result.getString("freereport"));
				computer = new Computer(this, resultArray.get(7));
				computer.setData(resultArray);				
			}
				i++;}
			writeToFile();
		} catch (SQLException e) {
			System.out.println("SQL Query hat einen Fehler verursacht");
			e.printStackTrace();
		}
	}
	public void writeToFile(){
		FileWriter writer = new FileWriter(additionalInformation, resultList);
		writer.write();
		float sldCResult = (float) sldC/numberOfSlds;
		float sldFResult = (float) (numberOfSlds-sldC)/numberOfSlds;
		System.out.println("SLDs korrekt: " + sldCResult + " | SLDs Falsch: " + sldFResult);
	}
}
